import java.io.File;
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        Scanner sr=new Scanner(System.in);
        String gs,tj="";
        int pd=0,num=0;
        System.out.println("请输入>>");
        gs=sr.nextLine();
        System.out.println("是否开启统计字的次数  输入1：开启");
        pd=sr.nextInt();
        sr.nextLine();
        if(pd==1){
            System.out.println("请输入需要统计的字符");
            tj=sr.nextLine();
        }
        try {
            File out=new File("D:/Desktop/编程类/编程/Java/StringUse/古诗词.txt");
            FileOutputStream s1=new FileOutputStream(out);
            OutputStreamWriter dos=new OutputStreamWriter(s1);
            for(int i=0;i<gs.length();i++){
                if("<未完，待续>".equals(gs.substring(i,i+7))){
                    dos.write("............");
                    break;
                }
                dos.write(gs.charAt(i));
                if((i+1)%7==0 && (i+1)%14!=0)
                    dos.write("，");
                else if((i+1)%14==0)
                    dos.write("。\n");
                if(pd==1){
                    if(tj.equals(gs.substring(i,i+tj.length())))
                        num+=1;
                }
                 }
             dos.close();
             }
        catch(Exception e){
            e.printStackTrace();
        }
        if(pd==1){
            System.out.println("统计的字符数："+num);
        }
    }
}
